 /**
 * Description: 客户端管理
 * @author:yueyemoyan
 * @since:1.0.0
 *
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2018-05-09   yueyemoyan       1.0.0     Initial
 */
package com.metro.activation.biz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.metro.activation.biz.beans.vo.BizClient;
import com.metro.activation.biz.mapper.IBizClientMapper;
import com.metro.activation.biz.service.inf.IBizClientService;
import com.metro.core.dao.IMapper;
import com.metro.core.service.BaseServiceSupport;
import com.metro.core.service.ServiceException;
import com.metro.core.vo.ResultCode;
import com.metro.core.vo.inf.IResult;

 /**
 * 客户端管理<br>
 *
 * @author:yueyemoyan
 * @since:1.0.0
 * @version [1.0.0, 2018-05-09]
 */
@Service("bizclientService")
public class BizClientService extends BaseServiceSupport<BizClient> implements IBizClientService{
    //客户端管理Mapper
    @Autowired
    private IBizClientMapper bizclientMapper;

    @SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
    public IMapper getMapper() {
        return bizclientMapper;
    }

    @Override
    public IResult save(BizClient entity) {
        try {
            bizclientMapper.save(entity);
            return ResultCode.SUCCESS;
        } catch (Exception e) {
            log.error("新增客户端管理失败", e);
            throw new ServiceException(ResultCode.ERROR);
        }
    }

    @Override
    public IResult update(BizClient entity) {
        try {
            bizclientMapper.update(entity);
            return ResultCode.SUCCESS;
        } catch (Exception e) {
            log.error("修改客户端管理失败", e);
            throw new ServiceException(ResultCode.ERROR);
        }
    }

    @Override
    public IResult delete(Long id) {
        try {
            bizclientMapper.delete(id);
            return ResultCode.SUCCESS;
        } catch (Exception e) {
            log.error("删除失败", e);
            throw new ServiceException(ResultCode.ERROR);
        }
    }

    @Override
    public IResult deleteByIds(String ids) {
        try {
            bizclientMapper.deleteByIds(ids);
            return ResultCode.SUCCESS;
        } catch (Exception e) {
            log.error("删除失败", e);
            throw new ServiceException(ResultCode.ERROR);
        }
    }

	@Override
	public IResult batchSave(List<BizClient> bizClientList) {
		try{
			bizclientMapper.batchSave(bizClientList);
			return ResultCode.SUCCESS;
		}catch(Exception e){
			log.error("导入失败", e);
			throw new ServiceException(ResultCode.ERROR);
		}
	}

	@Override
	public IResult cancelByIds(String ids) {
		try{
			bizclientMapper.cancelByIds(ids);
			return ResultCode.SUCCESS;
		}catch(Exception e){
			log.error("注销客户端失败", e);
			throw new ServiceException(ResultCode.ERROR);
		}
	}

	@Override
	public BizClient getLastByClientId(String clientId) {
		try{
			return bizclientMapper.getLastByClientId(clientId);
		}catch (Exception e) {
			log.error("根据客户端id查询失败", e);
			throw new ServiceException(ResultCode.ERROR);
		}
	}
}